/**
 * 
 */
package com.hexacta.hrs.web.struts.actions;

import org.vectrics.employee.Employee;
import org.vectrics.user.Person;

import com.hexacta.hrs.services.employee.EmployeeService;
import com.hexacta.hrs.services.person.PersonService;
import com.opensymphony.xwork2.ActionSupport;

/**
 * @author gvilla
 * 
 */
public class EditHiringConditionsAction extends ActionSupport {

    private static final String LIST = "list";

    private String userId;

    private String personId;

    private String hiringNotes;

    // private String previousNotes;

    private EmployeeService employeeService;

    private PersonService personService;

    public String editHiringConditions() {

        Employee employee = getEmployee();

        hiringNotes = employee.getHiringNotes();
        // previousNotes = hiringNotes;

        return SUCCESS;
    }

    public String save() {

        Employee employee = getEmployee();

        employee.setHiringNotes(hiringNotes);
        employeeService.update(employee);

        // previousNotes = hiringNotes;

        return LIST;
    }

    public String cancel() {

        // hiringNotes = previousNotes;

        return LIST;
    }

    /**
     * @return
     */
    private Employee getEmployee() {
        Person person = new Person();
        person.setId(Long.parseLong(personId));
        Employee employee = employeeService.searchByPerson(person);
        return employee;
    }

    /**
     * @return the userId
     */
    public String getUserId() {
        return userId;
    }

    /**
     * @return the personId
     */
    public String getPersonId() {
        return personId;
    }

    /**
     * @return the hiringNotes
     */
    public String getHiringNotes() {
        return hiringNotes;
    }

    /**
     * @param hiringNotes
     *            the hiringNotes to set
     */
    public void setHiringNotes(final String hiringNotes) {
        this.hiringNotes = hiringNotes;
    }

    /**
     * @param userId
     *            the userId to set
     */
    public void setUserId(final String userId) {
        this.userId = userId;
    }

    /**
     * @param personId
     *            the personId to set
     */
    public void setPersonId(final String personId) {
        this.personId = personId;
    }

    /**
     * @return the employeeService
     */
    public EmployeeService getEmployeeService() {
        return employeeService;
    }

    /**
     * @param employeeService
     *            the employeeService to set
     */
    public void setEmployeeService(final EmployeeService employeeService) {
        this.employeeService = employeeService;
    }

    public String getFullName() {
        return personService.getPersonById(Long.parseLong(personId)).getName();
    }

    /**
     * @return the personService
     */
    public PersonService getPersonService() {
        return personService;
    }

    /**
     * @param personService
     *            the personService to set
     */
    public void setPersonService(final PersonService personService) {
        this.personService = personService;
    }

    // /**
    // * @return the previousNotes
    // */
    // public String getPreviousNotes() {
    // return previousNotes;
    // }
    //
    // /**
    // * @param previousNotes
    // * the previousNotes to set
    // */
    // public void setPreviousNotes(final String previousNotes) {
    // this.previousNotes = previousNotes;
    // }

}
